﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T04//接口
{

    class Program
    {
        static void Main(string[] args)
        {
            BankCard b1 = new BankCard("b1");
            CreditCard b2 = new CreditCard("b2");
            BankCard b3 = new BankCard("b3");
            b3.money = 600;
            IPay[] pays = { b1, b2,b3 };
            foreach( IPay p in pays)
                if (p.pay(800))
                {if(p.findtype()=="借记卡")
                    Console.WriteLine("账号：{0} 账号类型：信用卡 状态：支付成功  余额：{1}",p.Getname(),p.Getmoney());
                else
                        Console.WriteLine("账号：{0} 账号类型：借记卡 状态：支付成功  欠款：{1}", p.Getname(), p.Getmoney());
                }
                else Console.WriteLine("账号：{0}  状态：支付失败!",p.Getname());
            Console.ReadKey();
        }
    }
    interface IPay//支付接口
    {
        bool pay(decimal price);//是否能支付
        string Getname();//获取用户名
        decimal Getmoney();//获取相关余额
        string findtype();//判断卡片类型
    }
    class BankCard :IPay//信用卡类
    {
        private string name;
        public BankCard(string name_)
        {
            name = name_;
        }
        public bool pay(decimal price)
        {
            if (money > price)
            {
                money -= price;
                return true;
            }
            else
                return false;
            throw new NotImplementedException();
        }

        public string Getname()
        {
            return name;
            throw new NotImplementedException();
        }

        public decimal Getmoney()
        {
            return money;
            throw new NotImplementedException();
        }

        public string findtype()
        {
            return "信用卡";
            throw new NotImplementedException();
        }

        public decimal money = 1000;

    }
    class CreditCard : IPay//借记卡类
    {
        public decimal overdrat=0;
        private string name;
        public CreditCard(string name_)
        {
            name = name_;
        }

        public string findtype()
        {
            return "借记卡";
            throw new NotImplementedException();
        }

        public decimal Getmoney()
        {
            return overdrat;
            throw new NotImplementedException();
        }

        public string Getname()
        {
            return name;
            throw new NotImplementedException();
        }

        public bool pay(decimal price)
        {
            overdrat += price;
            return true;
            throw new NotImplementedException();
        }
    }
}

